package com.view.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class LoginController extends AbstractController {

	private static final String CORRECT_USER_LOGIN = "viconte";
	private static final String CORRECT_USER_PASSWORD = "viconte123";
	private String helloString;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
//		<input type="hidden" id="hiddenLogin" />
//		<input type="hidden" id="hiddenPassword" />
		String userLogin = request.getParameter("hiddenLogin");
		String userPassword = request.getParameter("hiddenPassword");
		helloString = userLogin;
		if(CORRECT_USER_LOGIN.equals(userLogin) 
				&& CORRECT_USER_PASSWORD.equals(userPassword)
				){
			
			ModelAndView mv = new ModelAndView("loginPage");
			mv.addObject("userName" , "Viconte");
			return mv;
		}
		ModelAndView mv = new ModelAndView("loginFailured");
		mv.addObject("userName", helloString);
		return mv;
	}
}